﻿package mortal.game.view.achievement.panel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.achievement.data.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class AchievementRewardTipPanel extends GSprite
    {
        private var _bg:ScaleBitmap;
        private var _item:BaseItem;
        private var _nameTxt:GTextFiled;
        private var _desTxt:GTextFiled;
        private var _getBtn:GButton;
        private var _info:Object;
        protected var _layer:ILayer;

        public function AchievementRewardTipPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._layer = LayerManager.windowLayer;
            this._bg = UIFactory.bg(0, 0, 340, 80, this, ImagesConst.ChatMenuBg);
            this._item = UIFactory.getUICompoment(BaseItem, 10, 10, this);
            this._item.setItemStyle(ItemStyleConst.Mid);
            this._nameTxt = UIFactory.gTextField("" + Language.getString(70809), 124, 10, 164, 25, this);
            this._desTxt = UIFactory.gTextField("" + Language.getString(70810), 124, 36, 164, 25, this);
            this._getBtn = UIFactory.gButton("" + Language.getString(70811), 270, 36, 53, 27, this);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onOpenAchievementHd);
            return;
        }// end function

        public function updateByInfo(param1:Object) : void
        {
            var _loc_2:SAchievementCategory = null;
            var _loc_3:TAchievementCategory = null;
            var _loc_4:TAchievementCategoryRewards = null;
            var _loc_5:SAchievementType = null;
            var _loc_6:SAchievement = null;
            var _loc_7:TAchievement = null;
            this._info = param1;
            if (param1 is SAchievementCategory)
            {
                _loc_2 = param1 as SAchievementCategory;
                _loc_3 = AchievementConfig.instance.categoryObj[_loc_2.category];
                _loc_4 = AchievementConfig.instance.categoryRewardObj[param1.category + "_" + param1.level];
                if (_loc_3)
                {
                    this._nameTxt.text = "" + _loc_3.title;
                    this._item.itemCode = _loc_4.rewards;
                }
            }
            else if (param1 is SAchievementType)
            {
                _loc_5 = param1 as SAchievementType;
                _loc_6 = _loc_5.curAchievements[0];
                if (_loc_6)
                {
                    _loc_7 = AchievementConfig.instance.achievementObj[_loc_6.id];
                    this._nameTxt.text = "" + _loc_7.desc;
                    this._item.itemCode = int(_loc_7.rewards);
                }
            }
            return;
        }// end function

        public function show(param1:Object) : void
        {
            if (this.parent == null)
            {
                this._layer.addPopUp(this);
                this.updateByInfo(param1);
                this.onStageResize();
            }
            return;
        }// end function

        public function hide() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        private function onOpenAchievementHd(event:MouseEvent) : void
        {
            this.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementTipPanelCk, this._info));
            return;
        }// end function

        public function onStageResize() : void
        {
            this.x = (Global.stage.stageWidth - 340) / 2;
            this.y = Global.stage.stageHeight - 195;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._bg = null;
            this._nameTxt.dispose(param1);
            this._nameTxt = null;
            this._desTxt.dispose(param1);
            this._desTxt = null;
            this._item.dispose(param1);
            this._item = null;
            this._getBtn.dispose(param1);
            this._getBtn = null;
            if (this.parent == false)
            {
                this._layer.removePopup(this);
            }
            this._layer = null;
            return;
        }// end function

    }
}
